home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Atari Compendium
/
The Atari Compendium (Toad Computers) (1994).iso
/
files
/
umich
/
utils
/
pgp
/
pgp26uib.lzh
/
PGP26UI
/
DOC
/
PGFORMAT.DOC
< prev
next >
Wrap
Text File
|
1994-06-19
|
34KB
|
789 lines
Internal Data Structures Used by PGP 2.3 (14 Jun 93)
==========================================================
This appendix describes the file formats used externally by Pretty
Good Privacy (PGP), the RSA public key cryptography application. The
intended audience includes software engineers trying to port PGP to
other hardware environments or trying to implement other PGP-
compatible cryptography products, or anyone else who is curious.
[To be included: a description of ASCII armor. And ASCII armored
file is just like a binary file described here, but with an extra
layer of encoding added, framing lines, and a checksum at the end.]
Byte Order
----------
All integer data used by PGP is externally stored most significant
byte (MSB) first, regardless of the byte order used internally by the
host CPU architecture. This is for cross-compatibility of messages
and keys between hosts. This covers multiprecision RSA integers, bit
count prefix fields, byte count prefix fields, checksums, key IDs, and
timestamps.
The MSB-first byte order for external packet representation was
chosen only because many other crypto standards use it.
Multiprecision Integers
-----------------------
RSA arithmetic involves a lot of multiprecision integers, often
having hundreds of bits of precision. PGP externally stores a
multiprecision integer (MPI) with a 16-bit prefix that gives the
number of significant bits in the integer that follows. The integer
that follows this bitcount field is stored in the usual byte order,
with the MSB padded with zero bits if the bitcount is not a multiple
of 8. The bitcount always specifies the exact number of significant
bits. For example, the integer value 5 would be stored as these
three bytes:
00 03 05
An MPI with a value of zero is simply stored with the 16-bit bitcount
prefix field containing a 0, with no value bytes following it.
Key ID
------
Some packets use a "key ID" field. The key ID is the least
significant 64 bits of the RSA public modulus that was involved in
creating the packet. For all practical purposes it unique to each
RSA public key.
User ID
-------
Some packets contain a "user ID", which is an ASCII string that
contains the user's name. Unlike a C string, the user ID has a
length byte at the beginning that has a byte count of the rest of the
string. This length byte does not include itself in the count.
Timestamp
---------
Some packets contain a timestamp, which is a 32-bit unsigned integer
of the number of seconds elapsed since 1970 Jan 1 00:00:00 GMT. This
is the standard format used by Unix timestamps. It spans 136 years.
Cipher Type Byte (CTB)
----------------------
Many of these data structures begin with a Cipher Type Byte (CTB),
which specifies the type of data structure that follows it. The CTB
bit fields have the following meaning (bit 0 is the LSB, bit 7 is the
MSB):
Bit 7: Always 1, which designates this as a CTB
Bit 6: Reserved.
Bits 5-2: CTB type field, specifies type of packet that follows
0001 - public-key-encrypted packet
0010 - secret-key-encrypted (signature) packet
0101 - Secret key certificate
0110 - Public key certificate
1000 - Compressed data packet
1001 - Conventional-Key-Encrypted data
1011 - Raw literal plaintext data, with filename and mode
1100 - Keyring trust packet
1101 - User ID packet, associated with public or secret key
1110 - Comment packet
Other CTB packet types are unimplemented.
Bits 1-0: Length-of-length field:
00 - 1 byte packet length field follows CTB
01 - 2 byte packet length field follows CTB
10 - 4 byte packet length field follows CTB
11 - no length field follows CTB, unknown packet length.
The 8-, 16-, or 32-bit packet length field after the CTB
gives the length in bytes of the rest of the packet, not
counting the CTB and the packet length field.
RSA public-key-encrypted packet
-------------------------------
Offset Length Meaning
0 1 CTB for RSA public-key-encrypted packet
1 2 16-bit (or maybe 8-bit) length of packet
3 1 Version byte (=2). May affect rest of fields that follow.
4 8 64-bit Key ID
12 1 Algorithm byte for RSA (=1 for RSA).
--Algorithm byte affects field definitions that follow.
13 ? RSA-encrypted integer, encrypted conventional key
packet. (MPI with bitcount prefix)
The conventionally-encrypted ciphertext packet begins right after the
RSA public-key-encrypted packet that contains the conventional key.
Signature packet
----------------
Offset Length Meaning
0 1 CTB for secret-key-encrypted (signed) packet
1 2 16-bit (or maybe 8-bit) length of packet
3 1 Version byte (=2). May affect rest of fields that follow.
4 1 Length of following material that is implicitly included
in MD calculation.
5 1 Signature classification field (see below).
Implicitly append this to message for MD calculation.
6 4 32-bit timestamp of when signature was made.
Implicitly append this to message for MD calculation.
10 2 Validity period, in number of DAYS (0 means forever)
Implicitly append this to message for MD calculation.
12 8 64-bit Key ID
20 1 Algorithm byte for public key scheme (RSA=0x01).
--Algorithm byte affects field definitions that follow.
21 1 Algorithm byte for message digest (MD5=0x01).
22 2 First 2 bytes of the Message Digest inside the
RSA-encrypted integer, to help us figure out if we
used the right RSA key to check the signature.
24 ? RSA-encrypted integer, encrypted message digest
(MPI with bitcount prefix).
If the plaintext that was signed is included in the same file as the
signature packet, it begins right after the RSA secret-key-signed
packet that contains the message digest. The plaintext has a
"literal" CTB prefix.
The validity period field is generally only used for certifying keys.
It should be set to 0 otherwise, for regular message signatures. It
may be useful for PEM-like capabilities in future versions of PGP.
PGP 2.3 will always just set it to 0, and will ignore it.
There is a length field that specifies how many bytes of material is
implicitly included in the MD calculation. If this length field is
5, it means the following 1-byte classification field and the 4-byte
timestamp are included in the signature packet. If the length byte
is 7, it means the 2-byte validity period is also included. In PGP
2.3, we are using a length field of 5 for the material to be included
in the MD calculation, so the validity period is unused and
unincluded, and is assumed to be zeroed. This makes the whole
signature certificate shorter.
The signature classification field describes what kind of
signature certificate this is. There are various hex values:
00 - Signature of a message or document, binary image.
01 - Signature of a message or document, canonical text.
10 - Key certification, generic. Only version of key
certification supported by PGP 2.0.
Material signed is public key pkt and User ID pkt.
11 - Key certification, persona. No attempt made at all
to identify the user with a real name.
Material signed is public key pkt and User ID pkt.
12 - Key certification, casual identification. Some
casual attempt made to identify user with his name.
Material signed is public key pkt and User ID pkt.
13 - Key certification, positive ID. Heavy-duty
identification efforts, photo ID, direct contact
with personal friend, etc.
Material signed is public key pkt and User ID pkt.
20 - Key compromise. User signs his own compromise
certificate. Independent of user ID associations.
Material signed is public key pkt ONLY.
30 - Key/userid revocation. User can sign his own
revocation to dissolve an association between a key
and a user ID, or certifier may revoke his previous
certification of this key/userid pair.
Material signed is public key pkt and User ID pkt.
40 - Timestamping a